//
//  UIColor+DDAdd.h
//  AFNetworking
//
//  Created by 许龙 on 2019/9/24.
//

#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN

/*
Create UIColor with a hex string.
Example: UIColorHex(0xF0F), UIColorHex(66ccff), UIColorHex(#66CCFF88)

Valid format: #RGB #RGBA #RRGGBB #RRGGBBAA 0xRGB ...
The `#` or "0x" sign is not required.
*/
#ifndef UIColorHex
#define UIColorHex(_hex_) [UIColor colorWithHexString:((__bridge NSString *)CFSTR(#_hex_))]
#endif

#ifndef UIColorFromRGB
#define UIColorFromRGB(_hex_) [UIColor colorWithHexString:((__bridge NSString *)CFSTR(#_hex_))]
#endif

@interface UIColor (DDAdd)

/**
Creates and returns a color object from hex string.

@discussion:
Valid format: #RGB #RGBA #RRGGBB #RRGGBBAA 0xRGB ...
The `#` or "0x" sign is not required.
The alpha will be set to 1.0 if there is no alpha component.
It will return nil when an error occurs in parsing.

Example: @"0xF0F", @"66ccff", @"#66CCFF88"

@param hexStr  The hex string value for the new color.

@return        An UIColor object from string, or nil if an error occurs.
*/
+ (UIColor *)colorWithHexString:(NSString *)hexStr;

/**
 Creates and returns a color object from hex string and alpha.
 
 @discussion:
 Valid format: #RGB #RGB #RRGGBB #RRGGBB 0xRGB ...
 
 @param hexStr  The hex string value for the new color.
 @param alpha   range [0, 1]
 
 @return        An UIColor object from string, or nil if an error occurs.
 */
+ (UIColor *)colorWithHexString:(NSString *)hexStr alpha:(CGFloat)alpha;

/**
Creates and returns a color object using the hex RGBA color values.

@param rgbaValue  The rgb value such as 0x66ccffff.

@return           The color object. The color information represented by this
                  object is in the device RGB colorspace.
*/
+ (UIColor *)colorWithRGBA:(uint32_t)rgbaValue;

/**
Creates and returns a color object from a color to a color with percent
 
@param percent rang [0, 1]
 */
+ (UIColor *)colorByStartColor:(UIColor *)s endColor:(UIColor *)e percent:(CGFloat)percent;

/**
 Returns the rgba value in hex.
 
 @return hex value of RGBA,such as 0x66ccffff.
 */
- (uint32_t)rgbaValue;

@end

NS_ASSUME_NONNULL_END
